const express = require('express');
const app = express();
app.use(express.json());
app.use(express.urlencoded());

app.listen(80, () => console.log('服务启动'));

// 返回纯字符串
app.get('/api', (req, res) => {
  res.send('test3')
})

// 返回弹窗
app.get('/api2', (req, res) => {
  // 一个弹窗
  // res.send('MsgBox "test"')

  // 两个弹窗
  res.send('MsgBox "test 1"|MsgBox "test 2"')
})

// 条件代码块
app.get('/api3', (req, res) => {
  // 按正常代码行拆分（错误）
  // res.send('If 1 = 1 Then|MsgBox "test 1"|End If') 

  // 返回整个条件代码块
  res.send('If 1 = 1 Then MsgBox "test 1" Else MsgBox "test 2" End If')
})

// 配合子程序执行
app.get('/api4', (req, res) => {
  // 返回字符串直接调用子程序（错误）
  // res.send('If 1 = 1 Then Call runCodeBlock(MsgBox "test 1"|MsgBox "test 2") Else MsgBox "test3" End If')

  // 赋值到变量，在脚本中调用子程序
  res.send('subCode:MsgBox "test 1"|MsgBox "test 2"||If 1 = 2 Then codeBlock = list(0) Else MsgBox "test 3" End If')
})


// 获取下载图片名称及地址
app.get('/getUrlList', (req, res) => {
  res.send('D:\\bilibili.bmp|D:\\wx.bmp||http://localhost:80/api5|http://localhost:80/api6')
})
// 第一张图片
app.get('/api5', (req, res) => {
  res.download('bilibili.bmp')
})
// 第二张图片
app.get('/api6', (req, res) => {
  res.download('wx.bmp')
})
// 找图
app.get('/api7', (req, res) => {
  let code = ''
  code += 'subCode:MoveTo intX, intY|LeftClick 2'
  code += '||subCode:MsgBox "作者：酷玩蚊仔"|MsgBox "个人网站：http://www.kuwwz.com"'
  code += '||FindPic 0,0,1920,1080,"D:\\bilibili.bmp",0.9,intX,intY'
  code += '||If intX > 0 And intY > 0 Then codeBlock = list(0) Else codeBlock = list(1) End If'
  code += '||FindPic 1900,1000,1920,1080,"D:\\wx.bmp",0.9,intX,intY'
  code += '||If intX > 1 And intY > 1 Then codeBlock = list(0) Else codeBlock = list(1) End If'
  res.send(code)
})